package com.orion.schdule;

import com.orion.util.SmallTool;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * spring的schedule线程池默认只有一个线程
 *
 * 单个定时任务，每隔多少时间执行一遍
 *
 * @author Administrator
 */

@Component
@ConditionalOnProperty(value = "schedule.singlePreScheduleTask",havingValue = "true")
public class SinglePreScheduleTask {

    /**
     * 每隔2s执行一次
     */
    @Scheduled(cron = "0/2 * * * * ? ")
    public void JustScheduleForA() {
        SmallTool.printTimeAndThread("begin Just Schedule Task A ");
        SmallTool.sleepMillis(4000);
        SmallTool.printTimeAndThread("end Just Schedule Task A ");
    }

    /**
     * 单个任务：如果执行时长超过间隔。会等到任务执行完再等待设置的间隔 执行下一次任务，否则按照间隔来执行
     *
     1644732598006	|	30	|	scheduling-1	|	begin Just Schedule Task A
     1644732602009	|	30	|	scheduling-1	|	end Just Schedule Task A
     1644732604009	|	30	|	scheduling-1	|	begin Just Schedule Task A
     1644732608013	|	30	|	scheduling-1	|	end Just Schedule Task A
     1644732610029	|	30	|	scheduling-1	|	begin Just Schedule Task A
     1644732614031	|	30	|	scheduling-1	|	end Just Schedule Task A
     1644732616003	|	30	|	scheduling-1	|	begin Just Schedule Task A
     1644732620014	|	30	|	scheduling-1	|	end Just Schedule Task A
     */
}
